package com.fafa.File.Buffered;

import org.junit.Test;

import java.io.*;
import java.io.BufferedWriter;
import java.io.FileWriter;

//处理流的字符流
public class Buffered_Reader_Writer {
    public static void main(String[] args) {

    }

    @Test
    public void buffered_reader() throws IOException {
        File file = new File("E:\\1.txt");
        BufferedReader br = null;

        br = new BufferedReader(new FileReader(file));
        String line;
        //按行读取 返回 null文件读取完毕
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        //关闭流
        br.close();

    }

    @Test
    public void buffered_writer() throws IOException {
        String Filename = "E:\\1.txt";
        BufferedWriter bw = new BufferedWriter(new FileWriter(Filename,true));
        String str = "Hello World";
        bw.newLine();
        bw.write(str);

        bw.close();
    }
}


